package cn.kailangtu.dataspot.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;


import java.text.DecimalFormat;
import java.util.List;

import cn.kailangtu.dataspot.R;
import cn.kailangtu.dataspot.data.ExceptionData;

public class ExceptionLogAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater flater;
    private List<ExceptionData> data;


    public ExceptionLogAdapter(Context context, List<ExceptionData> data) {
        this.context = context;
        this.data = data;
       // flater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        flater = LayoutInflater.from(context);
    }

    public void setData(List<ExceptionData> data)
    {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        ExceptionData item = data.get(position);
        if (convertView == null) {
            //通过flater获取lis行对象
            convertView = flater.inflate(R.layout.item_exception_log_data, parent, false);
            holder = new ViewHolder();
            holder.tvLogContent = convertView.findViewById(R.id.tvExceptionLogContent);
            holder.tvLogId = convertView.findViewById(R.id.tvExceptionLogId);
            holder.tvLogTime = convertView.findViewById(R.id.tvExceptionLogTime);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }



        holder.tvLogId.setText(String.valueOf(item.getLogId()));
        holder.tvLogTime.setText(item.getLogTimeString());
        holder.tvLogContent.setText(item.getLogContent());

        return convertView;
    }

    static class ViewHolder{
        TextView tvLogId;
        TextView tvLogTime;
        TextView tvLogContent;
    }

}
